

<!DOCTYPE html>
<html>
<head>
  {include file="layout:_meta_index" /}
</head>
<body>

  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-header">修改密码</div>
      <div class="layui-card-body" pad15>

        <div class="layui-form" lay-filter="">
          <div class="layui-form-item">
            <label class="layui-form-label">当前密码</label>
            <div class="layui-input-inline">
              <input type="password" name="oldPassword" lay-verify="required" lay-verType="tips" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">新密码</label>
            <div class="layui-input-inline">
              <input type="password" name="password" lay-verify="required|pass" lay-verType="tips"  class="layui-input">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">确认新密码</label>
            <div class="layui-input-inline">
              <input type="password" name="repassword" lay-verify="required|repass" lay-verType="tips" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item">
            <div class="layui-input-block">
              <button class="layui-btn" lay-submit lay-filter="sysEdit">确认修改</button>
            </div>
          </div>
        </div>

      </div>
    </div>
  </div>

  {include file="layout:_footer" /}
  <script>
  layui.use(['form'],function () {
    var form = layui.form,$ = layui.$;

    form.verify({
      pass:function(value, item){
        if(value){
          if(!(/^[\w\W]{6,16}$/.test(value))){
            return '密码是6-16位的字母加数字';
          }
        }
      },
      repass: function (value, item) {
        if(value){
          var pass1 = $('input[name="password"]').val();
          var pass2 = $('input[name="repassword"]').val();
          if(pass1!=pass2){
            return '两次输入的新密码不一致';
          }
        }
      }
    });

    form.on('submit(sysEdit)', function(obj){
      $.post("{:url('admin/password')}", obj.field, function (res) {
        var icon = 5;
        if (res.code) {
          icon = 6;
        }
        layer.msg(res.msg, {icon: icon, time: 1500});
      }, 'json');
    });
  });
  </script>
</body>
</html>